<?php

require_once '../AopCertClient.php';
require_once '../AopCertification.php';
require_once '../request/AlipayTradeQueryRequest.php';
require_once '../request/AlipayTradeWapPayRequest.php';
require_once '../request/AlipayTradeAppPayRequest.php';


/**
 * 证书类型AopCertClient功能方法使用测试，特别注意支付宝根证书预计2037年会过期，请在适当时间下载更新支付更证书
 * 1、execute 证书模式调用示例
 * 2、sdkExecute 证书模式调用示例
 * 3、pageExecute 证书模式调用示例
 */


//1、execute 使用
$aop = new AopCertClient ();
/*$appCertPath = "应用证书路径（要确保证书文件可读），例如：/home/admin/cert/appCertPublicKey.crt";
$alipayCertPath = "支付宝公钥证书路径（要确保证书文件可读），例如：/home/admin/cert/alipayCertPublicKey_RSA2.crt";
$rootCertPath = "支付宝根证书路径（要确保证书文件可读），例如：/home/admin/cert/alipayRootCert.crt";*/
$appCertPath = "C:/Users/Administrator/IdeaProjects/zhouwunahui/cert/appCertPublicKey_2021003160688225.crt";
$alipayCertPath = "C:/Users/Administrator/IdeaProjects/zhouwunahui/cert/alipayCertPublicKey_RSA2.crt";
$rootCertPath = "C:/Users/Administrator/IdeaProjects/zhouwunahui/cert/alipayRootCert.crt";

$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = '2021003160688225';
$aop->rsaPrivateKey = 'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC+F9Czb4OeaD7DG75mHs1POjYi42p9fBKAotgAqVCviPIqKR8v+jOtGPSQ7m6fOpcwnTlzFqb8Mhz0gDbiVcAJ+0o2BuZLV9uwCcK/I+h9lg5usXIN7A+RNm0a47P/Xw6rwY3naYieOfHETf4HhyfLsW/eKx55k94gXxho7Pj5R1ab1cGy8FZmzb+x04LgJQE4y1/jc5fL8QUDox0tHEg6h4z7kLEKqTzc2uwO0/cD+c8lry8/lSz7OMCt9HFJhF4hVfEIX9SewuXoLys+f3Y2xapE7UBHz3/aX8QWfv8nJV1nkgHWgf194WycCrV3kHk03SCfiCj9gPMp4sIx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pwHGNrXhGEZIpPBBYdh2NPdqeqRdRBe5yr3hvUWc/oYKn4x3s6IHCSs+wvamTWS167tsmYTyGXWfQZkkiJ05xQG4PpUupssOZu33v0mOjuBRSxoIBB/wIiB2z0nh/ORm5Q5+lgx34MZZo3YTPCg1ypmj/MbA==';
$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//调用getPublicKey从支付宝公钥证书中提取公钥
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset = 'utf-8';
$aop->format = 'json';
$aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书，如果开启校验要保证支付宝根证书在有效期内
$aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
$aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号

/*$request = new AlipayTradeQueryRequest ();
$request->setBizContent("{" .
    "    \"out_trade_no\":\"7589451258121548951215651236\"," .
    "    \"total_amount\":\"0.01\"," .
    "    \"subject\":\"测试\"" .
    "  }");
$result = $aop->execute($request);*/
$object = new stdClass();
$object->out_trade_no = '7589451258121548951215651236';
$object->total_amount = 0.01;
$object->subject = '测试商品';
$object->product_code ='QUICK_WAP_WAY';
$object->time_expire = '2022-11-19 21:00:00';
$json = json_encode($object);
$request = new AlipayTradeWapPayRequest();
$request->setNotifyUrl('http://api.zhwnh.cn/Pay/alipayCallback');
$request->setReturnUrl('http://api.zhwnh.cn/web');
$request->setBizContent($json);
$result = $aop->pageExecute ( $request);

/*$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
    echo "成功";
} else {
    echo "失败";
}*/
var_dump($result);
